package com.foreveross.framework.example.tags.controller;

import com.foreveross.framework.example.tags.service.CityService;
import com.foreveross.framework.example.tags.ztree.TreeNode;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class TreeController {

  @Autowired
  private CityService cityService;

  @RequestMapping(value = "/example/tree", method = RequestMethod.GET)
  public String execute(ModelMap modelMap) {
    return "example/tree";
  }

  @ResponseBody
  @RequestMapping(value = "/example/tree/data")
  public List<TreeNode> data() {
    List<TreeNode> root = Lists.newArrayList();

    TreeNode n1 = new TreeNode("n1", true);
    root.add(n1);
    TreeNode n11 = new TreeNode("n11");
    n11.setChecked(true);
    n1.getChildren().add(n11);
    TreeNode n12 = new TreeNode("n12");
    n12.setChkDisabled(true);
    n1.getChildren().add(n12);

    TreeNode n2 = new TreeNode("n2");
    n2.setOpen(true);
    root.add(n2);
    n2.getChildren().add(new TreeNode("n21"));
    n2.getChildren().add(new TreeNode("n22"));

    TreeNode n3 = new TreeNode("n3");
    root.add(n3);
    n3.getChildren().add(new TreeNode("n31"));
    n3.getChildren().add(new TreeNode("n32"));

    return root;
  }

}
